package cn.iocoder.yudao.module.reading.controller.app.assignment.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 班级作业汇总 Response VO
 *
 * @author 芋道源码
 */
@Schema(description = "用户 APP - 班级作业汇总 Response VO")
@Data
public class ClassAssignmentSummaryRespVO {

    @Schema(description = "班级ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long classId;

    @Schema(description = "班级名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "一年级1班")
    private String className;

    @Schema(description = "班级总人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "30")
    private Integer totalMembers;

    @Schema(description = "作业总数", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
    private Integer totalAssignments;

    @Schema(description = "已完成作业数", requiredMode = Schema.RequiredMode.REQUIRED, example = "3")
    private Integer completedAssignments;

    @Schema(description = "进行中作业数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer inProgressAssignments;

    @Schema(description = "未开始作业数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer notStartedAssignments;

    @Schema(description = "逾期作业数", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    private Integer overdueAssignments;

    @Schema(description = "班级整体完成率", requiredMode = Schema.RequiredMode.REQUIRED, example = "75.5")
    private Double overallCompletionRate;

    @Schema(description = "最近更新时间")
    private LocalDateTime lastUpdateTime;

    @Schema(description = "作业详细统计列表")
    private List<AssignmentSummary> assignmentSummaries;

    @Data
    @Schema(description = "作业统计摘要")
    public static class AssignmentSummary {
        @Schema(description = "作业ID", example = "1")
        private Long assignmentId;

        @Schema(description = "作业标题", example = "第一周阅读作业")
        private String title;

        @Schema(description = "作业日期")
        private LocalDateTime assignmentDate;

        @Schema(description = "总绘本数", example = "3")
        private Integer totalBooks;

        @Schema(description = "已完成人数", example = "25")
        private Integer completedCount;

        @Schema(description = "未完成人数", example = "5")
        private Integer incompleteCount;

        @Schema(description = "完成率", example = "83.33")
        private Double completionRate;

        @Schema(description = "是否逾期", example = "false")
        private Boolean isOverdue;

        @Schema(description = "作业状态", example = "进行中")
        private String status;
    }

    /**
     * 计算班级整体完成率
     */
    public void calculateOverallCompletionRate() {
        if (totalAssignments != null && totalAssignments > 0) {
            this.overallCompletionRate = Math.round((double) completedAssignments / totalAssignments * 100 * 100.0) / 100.0;
        } else {
            this.overallCompletionRate = 0.0;
        }
    }
}
